import pandas as pd
from sklearn.metrics import accuracy_score
import joblib
from util.commonUtil import mean_absolute_percentage_error
from sklearn.metrics import roc_auc_score, accuracy_score, roc_curve
import transform_test
import matplotlib.pyplot as plt


def xgb_predict():
    # 读取数据
    x_test, y_test = transform_test.tes1_do()
    x_test_xgb = x_test.iloc[:, 0:20].copy()

    # 模型读取
    model_xgb = joblib.load('../model/xgb.pkl')
    # 预测类别（用于准确率）
    y_pred = model_xgb.predict(x_test_xgb)
    # 预测概率(用于 ROC AUC)
    y_pred_proba = model_xgb.predict_proba(x_test_xgb)[:, 1]

    auc = roc_auc_score(y_test, y_pred_proba)
    accuracy = accuracy_score(y_test, y_pred)

    print(f'预测值: {y_pred}')
    print(f'准确率: {accuracy:.4f}')
    print(f'AUC值: {auc:.4f}')


if __name__ == '__main__':
    xgb_predict()